<?php
/**
 * 画像管理
 */
namespace app\passport\model;
use think\Model;

class Face extends Model{

    protected $pk       = 'id';
    protected $table    = 'sp_passport_face';
    protected $autoWriteTimestamp = true;
    protected $pageNumber = 20;

    /**
     * 单个
     * @param int $param
     * @return array
     */
    public function find_info($param) {
        return self::get($param);
    }

    /**
     * 列表
     * @access public
     * @param array $where
     */
    public function select_lists(){
        return $this->order('id desc')->paginate($this->pageNumber);
    }

    /**
     * sp_passport_face_anyang 列表
     * @access public
     * @param array $where
     */
    public function face_student($where = []){
        if(count($where)){
            $name = [];
            if($where['name']){
                $name['name'] = $where['name'];
            }
            return $this->table('sp_passport_face_anyang')
                ->where($name)
                ->where('phone','like','%'.$where['phone'].'%')
                ->where('work','like','%'.$where['work'].'%')
                ->order('id desc')
                ->paginate($this->pageNumber,false,['query'=>$where]);
        }
        return $this->table('sp_passport_face_anyang')->order('id desc')->paginate($this->pageNumber);
    }
    /**
     * sp_passport_face_anyang 统计
     * @access public
     * @param array $where
     */
    public function face_student_counts($where = []){
        if(count($where)){
            $name = [];
            if($where['name']){
                $name['name'] = $where['name'];
            }
            return $this->table('sp_passport_face_anyang')
                ->where($name)
                ->where('phone','like','%'.$where['phone'].'%')
                ->where('work','like','%'.$where['work'].'%')
                ->count();
        }
        return $this->table('sp_passport_face_anyang')->count();
    }



    /**
     * 添加
     * @param array $param
     * @return int
     */
    public function add_data($param) {
        $data = [
            'face_name'   => $param['face_name'],
            'table_name'  => $param['table_name'],
            'about'       => $param['about'],      
            'create_time' => time(),
            'update_time' => time(),
        ];
        return $this->insertGetId($data);
    }
    
    /**
     * 编辑
     * @param type $param
     */
    public function edit_data($param) {
        $data = [
            'face_name'   => $param['face_name'],
            'about'       => $param['about'],      
            'update_time' => time(),
        ];
        $where = ['id'=>$param['id']];
        return $this->where($where)->update($data);
    }
}